package com.umanji.category.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.IndexColumn;

import com.umanji.generic.entity.UUIDEntity;
import com.umanji.usedmarket.domain.UsedProducts;

@Entity
@Table(name="categories")
public class Categories extends UUIDEntity<Categories> {

    @Column(name = "category_name", unique = false, nullable = false)
    @NotNull
    @Size(min = 5, max = 50)
    private String CategoryName;

    @Column(name = "category_code", unique = true, nullable = false)
    @NotNull
    @Size(min = 3, max = 15)
    private String CategoryCode;

	@ManyToOne()
	@JoinColumn(name="parent", insertable=false, updatable=false, nullable=true)
    private Categories parent;

    @OneToMany
    @JoinColumn(name="used_product_id")
    private List<UsedProducts> UsedProducts;

	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
	@Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
	@JoinColumn(name="parent", nullable=true)
	private List<Categories> children;

    private int CategoryOrder;

	public Categories() {
		// TODO Auto-generated constructor stub
	}

    public Categories(String categoryName, String categoryCode, Categories parent, int categoryOrder) {
        this.CategoryName = categoryName;
        this.CategoryCode = categoryCode;
        this.parent = parent;
        this.CategoryOrder = categoryOrder;
    }

    public Categories(String categoryName, String categoryCode, int categoryOrder) {
        this.CategoryName = categoryName;
        this.CategoryCode = categoryCode;
        this.CategoryOrder = categoryOrder;
    }

    /*
	@Column(insertable = false, updatable = false, nullable=false)
    public UUID getId() {
        return super.getId();
    }

    public void setId(UUID uuid) {
        super.setId(uuid);
    }
    */


	public List<Categories> getChildren() {
	   return children;
	}

	public void setChildren(List<Categories> children) {
	   this.children = children;
	}

	public String getCategoryCode() {
		return CategoryCode;
	}

	public void setCategoryCode(String CategoryCode) {
		this.CategoryCode = CategoryCode;
	}

	public String getCategoryName() {
		return CategoryName;
	}

	public void setCategoryName(String CategoryName) {
		this.CategoryName = CategoryName;
	}

	public Categories getParent() {
		return parent;
	}

	public void setParent(Categories parent) {
		this.parent = parent;
	}

	public int getCategoryOrder() {
		return CategoryOrder;
	}

	public void setCategoryOrder(int categoryOrder) {
		this.CategoryOrder = categoryOrder;
	}

	public List<UsedProducts> getUsedProducts() {
		return UsedProducts;
	}

	public void setUsedProducts(List<UsedProducts> usedProducts) {
		UsedProducts = usedProducts;
	}
    
}
